<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class AgentAuth extends Base
{
    protected $insert = ['addtime'];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }
    
    public function getAddtimeTextAttr($value, $data){
        return date('Y-m-d H:i:s', $data['addtime']);
    }

    public function getAgentUserNameAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('usename');
    }

    public function getAgentUserTitleAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('title');
    }
    public function getAgentUserLevelAttr($value,$data){
         $agent = (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->find();
         $data = (new \app\common\model\Level())->where(['id' => $agent['level_id']])->find();
         return empty($data) ? '无限制' : $data;
    }
    public function getAuthTextAttr($value,$data){
        return (new \app\common\model\AgentAdminAuth())->whereIn('id',$data['auth_id'])->column('title');
    }
    public function getEndtimeTextAttr($value,$data){
        return $data['endtime'] == 0 ? '长期' : date('Y-m-d H:i:s', $data['endtime']);
    }
}
